    <template>
         <div id="contain">
             <div id="regist">
                <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                    <!-- 后台管理中心 -->
                    <div class="regist_login">
                     <!-- <el-button>登录</el-button><el-button>注册</el-button> -->
                     <router-link to="Login">登录</router-link>&nbsp;&nbsp;<router-link to="Regist"> 注册</router-link>
                    </div>
                    <div class="title">
                       后台管理中心
                    </div>
                     <el-form-item label="工号" prop="idNum">
                        <el-input v-model="ruleForm.idNum"></el-input>
                    </el-form-item>
                     <el-form-item label="姓名" prop="name">
                        <el-input v-model="ruleForm.name"></el-input>
                    </el-form-item>
                    <el-form-item label="密码" prop="pass">
                        <!-- <el-input v-model="ruleForm.pass"></el-input> -->
                        <el-input  v-model="ruleForm.pass" show-password></el-input>
                    </el-form-item>
                      <el-form-item label="验证码" prop="yzm">
                        <div class="yz"><el-input class="yzm" v-model="yzm.checkYzm"></el-input>
                            <input type="button"  @click="createCode"  class="verification" v-model="yzm.checkCode"/>
                        </div> 
                    </el-form-item>
                     <el-form-item>
                        <el-button type="primary" class="loginBut" @click="login">登录</el-button>
                    </el-form-item>
                </el-form>
             </div>
         </div>
    </template>
    
    <script>
    var code='';
      export default {
    data() {
      var checkIdNum=(rule,value,callback)=>{
          if (!value) {
          return callback(new Error('工号不能为空'));
        }
        callback();
      }
      var checkName = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('姓名不能为空'));
        }
        callback();
      };
        var checkPass = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('密码不能为空'));
        }
        callback();
      };
      //  var checkYzm = (rule, value, callback) => {
      //   if (!value) {
      //     return callback(new Error('验证码不能为空'));
      //   }
      //   callback();
      //  };

      return {
         coupon:{},
         id:'',
         time:0,
         phone:'',
         name:'',
         address:'',
         message:'',
         yzm:{
            checkCode:'',
            checkYzm:''
         },
        //  checkCode:'',
         picLyanzhengma:'',
        ruleForm: {
          idNum:'',
          pass:'',
          name:'',
          // yzm:''
        },
        rules: {
          idNum:[
              { validator: checkIdNum, trigger: 'blur' }
          ],
          pass: [
            { validator: checkPass, trigger: 'blur' }
          ],
          name: [
            { validator: checkName, trigger: 'blur' }
          ],
          // yzm: [
          //   { validator: checkYzm, trigger: 'blur' }
          // ]
        }
      };
    },
    mounted(){
  
    },
    created(){
      this.createCode();
    },
    methods: {
      // 图片验证码
    createCode(){
                 //先清空验证码的输入
                 this.code = "";
                 this.yzm.checkCode = "";
                 this.picLyanzhengma = "";
                 //验证码的长度  
                    var codeLength = 4; 
                    //随机数 
          var random = new Array(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');  
          for(var i = 0; i < codeLength; i++) {
                        //取得随机数的索引（0~35）
                            var index = Math.floor(Math.random()*36);   
                            //根据索引取得随机数加到code上
              this.code += random[index];   
                    }
                    //把code值赋给验证码  
          this.yzm.checkCode = this.code; 
      },
       login:function(){
           this.$http.post("http://"+this.GLOBAL.ipAddress+":8080/admin/comCode",this.yzm)
           .then(function(data){
             console.log(data.bodyText)
             if(data.bodyText=="ok"){
                 this.$http.post("http://"+this.GLOBAL.ipAddress+":8080/admin/login",this.ruleForm)
                .then(function(data){
                console.log(data.bodyText)
                if(data.bodyText=="admin"){
                 var ses=window.localStorage;
                 var d=this.ruleForm.name
                 var j=this.ruleForm.idNum
                 var apwd=this.ruleForm.pass
                 ses.setItem('aname',d)
                 ses.setItem('anum',j)
                 ses.setItem('apwd',apwd)
                 console.log("anum:"+window.localStorage.getItem('anum'))
                   this.$router.push({path:'/manage'});
                }else if(data.bodyText=="doctor"){
                var ses=window.localStorage;
                 var d=this.ruleForm.name
                 var j=this.ruleForm.idNum
                 var dpwd=this.ruleForm.pass
                 ses.setItem('dname',d)
                 ses.setItem('jnum',j)
                 ses.setItem('dpwd',dpwd)
                 
                //  console.log('jnum'+window.localStorage.getItem('jnum'))
                 this.$router.push({path:'/check'});
                }else if(data.bodyText=="no"){
                  alert("您无权访问")
                }
                else{
                    alert("用户信息输入有误");
                }
                  })
             }
             else
               alert("有误")
           })
       },
       getyzm(){
          this.$http.get("http://"+this.GLOBAL.ipAddress+":8080/admin/getPass").then(function(data) {
         this.yzm2 = data.body;
         
        });
       }
  }
  }
    </script>
    
    <style>
    .router-link-active {
      text-decoration: none;
    }
    a{
      text-decoration: none;
    }
    .yanzhengma_input{
        font-family: 'Exo 2', sans-serif;
    border: 1px solid #fff;
    color: #fff;
    outline: none;
    border-radius: 12px;
    letter-spacing: 1px;
    font-size: 17px;
    font-weight: normal;
        background-color: rgba(82, 56, 76, 0.15);
        padding: 5px 0 5px 10px;
    margin-left: 30px;
    height: 30px;
    margin-top: 25px;
    border: 1px solid #e6e6e6;
}

.captcha{
    height: 50px;
    text-align: justify;
}
    .title{
        font-size: 22px;
        font-weight: 500;
        text-align: center;
       margin-left: 70px;
       margin-bottom: 40px;
    }
    #regist{
        margin-left: 400px;
        margin-top: 10px;
        margin-bottom: 10px;
        padding-top: 65px;
        padding-right: 70px;
        text-align: center;
        height: 500px;
        width: 400px;
        background-color: white;
        opacity: 0.7;
        position: relative;
       border-radius: 8px;
       /* font-weight: bolder; */
    }
    /* .yz{
      height: 50px;
    } */
    .yzm{
      width: 170px;
      /* padding-left: 0px; */
      /* margin-left: 0px; */
    }
    .verification{
    border-radius: 12px;
    width:100px;
    letter-spacing:5px;
    margin-left: 20px;
    height: 40px;
    transform: translate(-15px,0);
}


    .active{
      color: brown;
    }
    .loginBut{
         width: 300px;
    }
     .regist_login{
      margin-bottom: 15px;
      position: absolute;
      left: 50px;
      top: 25px;
      color: black;
    }
    </style>

